/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.guide.web;

import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.utils.CacheUtils;
import com.jeeplus.common.utils.PageBean;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.guide.entity.YmbcsUser;
import com.jeeplus.modules.guide.entity.YmbcsValue;
import com.jeeplus.modules.guide.model.query.ServiceOfficesQuery;
import com.jeeplus.modules.guide.service.*;
import com.jeeplus.modules.guide.task.ManageDuration;
import com.jeeplus.modules.guide.task.Send;
import com.jeeplus.modules.guide.utils.*;
import com.jeeplus.modules.sys.entity.MobileGxUser;
import com.jeeplus.modules.sys.entity.MobileUserQR;
import com.jeeplus.modules.sys.entity.YmbcsUserZF;
import com.jeeplus.modules.sys.service.UserService;
import com.jeeplus.modules.sys.utils.Des3Utils;
import com.jeeplus.modules.sys.utils.EncryptUtils;
import com.jeeplus.modules.sys.utils.FileKit;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.work.queue.service.ElectronicMaterialService;
import com.jeeplus.modules.work.queue.utils.QueueSend;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 无声叫号Controller 微信/短信/语音模式
 *
 * @author azj
 * @version 2020-04-24
 */
@RestController
@Api(tags = "排号接口")
@RequestMapping(value = "/mobileSilent")
@RequiredArgsConstructor
public class MobileSilentController extends BaseController {
    /**
     * 监察对接
     */
    private final QueueSend queueSend;
    private final MobileSilentService mobileSilentService;
    private final MobileQueueService mobileQueueService;
    private final MobileMatterService mobileMatterService;
    private final Send send;
    private final UserService userService;
    private final VersionService versionService;
    private final ManageDuration manageDuration;
    private final MobileIndexService mobileIndexService;
    private final AppointmentService appointmentService;
    private final ElectronicMaterialService electronicMaterialService;

    //电子社保卡配置 详情看配置解析 pz
    @Value("${pz_ybj_url}")
    private String pz_ybj_url;
    @Value("${pz_ybj_accessKey}")
    private String pz_ybj_accessKey;
    @Value("${pz_ybj_privateKey}")
    private String pz_ybj_privateKey;
    @Value("${pz_ybj_appid}")
    private String pz_ybj_appid;
    @Value("${pz_ybj_appSecret}")
    private String pz_ybj_appSecret;



    //电子社保卡配置 详情看配置解析
    @Value("${ybj_url}")
    private String ybj_url;
    @Value("${ybj_accessKey}")
    private String ybj_accessKey;
    @Value("${ybj_privateKey}")
    private String ybj_privateKey;
    @Value("${ybj_appid}")
    private String ybj_appid;
    @Value("${ybj_appSecret}")
    private String ybj_appSecret;
    //二维码失效时间
    @Value("${loseTime}")
    private int loseTime;
    //腾讯云 SecretId
    @Value("${SecretId}")
    private String SecretId;
    //腾讯云 SecretKey
    @Value("${SecretKey}")
    private String SecretKey;
    //微信AppID
    @Value("${AppID}")
    private String AppID;
    //微信AppSecret
    @Value("${AppSecret}")
    private String AppSecret;
    //微信获取openid跳转url
    @Value("${CodeUrl}")
    private String CodeUrl;
    //用户扫描排号机二维码跳转url
    @Value("${toPage}")
    private String toPage;
    private static final Logger logger = LoggerFactory.getLogger(MobileSilentController.class);
    //对接AppKeyValue
    @Value("${AppKeyValue}")
    private String AppKeyValue;
    //跳转至二维码 获取排队信息并无声叫号
    @Value("${toUrl}")
    private String toUrl;
    //私钥
    @Value("${GX_PUBLIC_KEY}")
    private String GX_PUBLIC_KEY;
    //对接公安的排队叫号状态路径
    @Value("${gongAnUrl}")
    private String gongAnUrl;
    //对接公安的排队叫号状态路径
    @Value("${gongAnOrgrizeId}")
    private String gongAnOrgrizeId;
    //获取直接人脸验证后台传身份信息验证 自助取件柜人脸验证页面 获取二维码扫码url内容
    @Value("${faceCheckQR}")
    private String faceCheckQR;
    //是否为人才判断
    @Value("${userCheckRC}")
    private String userCheckRC;

    //排队叫号QueueUrl
    @Value("${QueueUrl}")
    private String QueueUrl;
    /**
     * 排队等待测试
     */
    @GetMapping("queueTest")
    public Map<String, Object> queueTest(String number,String areaId){
        //排队等待测试
        return  mobileSilentService.getQueueValue(number, areaId);
    }

    /**
     * insertQueueValueByCode 获取微信用户基础信息数据记录并发送等待通知 -微信
     * areaId点位标识
     * number 排队编号
     * 微信跳转携带的参数 code用于获取用户微信数据
     * @author azj
     * @version 2020-04-24
     */
    @GetMapping("insertQueueValueByCode")
    public void insertQueueValueByCode(String isSend,String areaId, String number, String tell, String code, HttpServletResponse response) {
        if (StringUtils.isNotBlank(code) && StringUtils.isNotBlank(number) && StringUtils.isNotBlank(areaId)) {
            //微信基础信息获取并记录
            // 获取openid请求
            String url = WeiXinConfig.getOpenId;
            String param = WeiXinConfig.openIdParam.replace("AppId", AppID).replace("AppSecret",
                    AppSecret).replace("CODE", code);
            // 获取微信用户opendid
            String result = HttpRequestUtil.sendPost(url, param);
            if(null != result){
                JSONObject jsonObject = JSONObject.fromObject(result);
                String openid = jsonObject.getString("openid");
                if(!"510109001000".equals(areaId) && send.checkUserWx(openid) == null){
                    try {
                        response.sendRedirect(toPage + "4");
                    }catch (Exception e){}
                }
                //异步微信基础信息添加
                Boolean flag = mobileSilentService.insertValue(number, areaId, openid, null, null,tell,0);
                //获取排队结果
                Map<String, Object> map = mobileSilentService.getQueueValue(number, areaId);
                //异步发送信息
                String areaNameValue = mobileSilentService.findAreaNameValue(areaId);
                if(StringUtils.isNotBlank(areaNameValue)){
                    number = number+"("+areaNameValue+")";
                }
                if(flag){
                    if(!WeiXinConfig.isSend.equals(isSend)){
                        //异步请求
                        send.getWXInfoAsync(openid,number,map,tell,areaId);
                    }
                }
                //重定向前端页面
                try{
                    //判断是否已发送排队信息
                    //异步微信推送
                    if(null == map.get("wino")){
                        response.sendRedirect(toPage+"2"+"&number="+java.net.URLEncoder.encode(String.valueOf(number), "UTF-8")+"&num="+java.net.URLEncoder.encode(String.valueOf(map.get("num")), "UTF-8")+"&areaName="+java.net.URLEncoder.encode(String.valueOf(map.get("areaName")), "UTF-8")+"&typeName="+java.net.URLEncoder.encode(String.valueOf(map.get("typeName")), "UTF-8")+"&waitTime="+java.net.URLEncoder.encode(String.valueOf(map.get("waitTime")), "UTF-8")+"&waitDoTime="+java.net.URLEncoder.encode(String.valueOf(map.get("waitDoTime")), "UTF-8"));
                    }else{
                        response.sendRedirect(toPage+"2&wino="+map.get("wino")+"&number="+java.net.URLEncoder.encode(String.valueOf(number), "UTF-8")+"&num="+java.net.URLEncoder.encode(String.valueOf(map.get("num")), "UTF-8")+"&areaName="+java.net.URLEncoder.encode(String.valueOf(map.get("areaName")), "UTF-8")+"&typeName="+java.net.URLEncoder.encode(String.valueOf(map.get("typeName")), "UTF-8")+"&waitTime="+java.net.URLEncoder.encode(String.valueOf(map.get("waitTime")), "UTF-8")+"&waitDoTime="+java.net.URLEncoder.encode(String.valueOf(map.get("waitDoTime")), "UTF-8"));
                    }
                }catch (Exception e){
                    logger.error("手机扫面页面跳转失败："+e.getMessage());
                }
            }else{
                logger.error("number：" + number+" reason : sendPost get openid is error");
                //重定向前端页面
                try{
                    response.sendRedirect(toPage + "3");
                }catch (Exception e){
                    logger.error("手机扫面页面跳转失败："+e.getMessage());
                }
            }
        } else {
            //重定向前端页面
            try{
                response.sendRedirect(toPage + "3");
            }catch (Exception e){
                logger.error("手机扫面页面跳转失败："+e.getMessage());
            }
        }
    }

    /**
     * inserQueueBySMS 获取微信用户基础信息数据记录并发送等待通知 -短信/语音
     * status:1表述语音拨打 0不是
     *  areaId点位标识
     *  number排队编号
     *  tell手机号
     * @author azj
     * @version 2020-04-24
     */
    @GetMapping("insertQueueBySMS")
    public AjaxJson insertQueueBySMS(String areaId, String number, String tell){
        if (StringUtils.isNotBlank(tell) && StringUtils.isNotBlank(number) && StringUtils.isNotBlank(areaId)) {
            //异步执行 短信信息记录
            send.getSMSInfo(areaId, number, tell,0);
            //返回查询结果
            Map<String, Object> map = mobileSilentService.getQueueValue(number, areaId);
            send.sendSMSQueueInfo(tell,number,map);
            return AjaxJson.success();
        } else {
            return AjaxJson.error("inserQueueBySMS data is null");
        }
    }

    //推送当前叫号以及后续3，6位等待
    public void toSendSMSAndWX(String areaId, String number, String winNo,String areaNameValue){
        send.getWXInfo();
        send.toQueueValuesOne(areaId,number,winNo,areaNameValue);
        send.toQueueValuesTwo(areaId,number,winNo,areaNameValue);
    }
    //仅发送当前叫号
    public void toOnlySendSMSAndWX(String areaId, String number, String winNo,String areaNameValue){
        send.getWXInfo();
        send.toQueueValuesOne(areaId,number,winNo,areaNameValue);
    }


    //自动跳转至获取微信信息
    @GetMapping("/toUrl")
    public void toUrl(String isSend,String tell,String areaId,String number,HttpServletResponse response) {
        send.intoUserHistory(-1, 0, tell, areaId, number, null, null, null, null,null);
        if (StringUtils.isNotBlank(areaId) && StringUtils.isNotBlank(number)) {
            String url = WeiXinConfig.getCodeUrl;
            try {
                // 授权获取openid
                String encode = URLEncoder.encode(CodeUrl
                        + "?isSend="+isSend+"&areaId=" + areaId + "&number=" + number +  "&tell="+ tell, "utf-8");
                url = url.replace("$appid", AppID).replace(
                        "$redirect_uri", encode);
                response.sendRedirect(url);
            } catch (Exception e) {
                logger.error("number:" + number +" reason: "+e.getMessage());
            }
        }
    }

    //自动跳转至获取微信信息
    @PostMapping("/toSendZF")
    public AjaxJson toSendZF(@RequestHeader("AppKey") String AppKey,String title,String doTime,String typeName,String status,String idcard) {
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        String opnid = mobileMatterService.findWXIdByIdcard(idcard);
        if(StringUtils.isNotBlank(opnid)){
            send.getWXInfo();
            send.sendLineWXZF(title,doTime,typeName,status,opnid);
            return AjaxJson.success("操作成功！");
        }else{
            return AjaxJson.error("idcard is not WXid!").put("code", 400);
        }

    }

    /**
     * getUrl 跳转授权获取微信用户基础信息openid  微信、微信+短信
     * areaId 点位标识
     * number 排队编号
     * winNo 可办窗口号
     * waitNo 等待人数
     * @author azj
     * @version 2020-04-24
     */
    public AjaxJson getUrl(String areaId, String number, String tell,String url,int waitNum,String yyID,String areaNameValue) {
        if (StringUtils.isNotBlank(areaId) && StringUtils.isNotBlank(number)) {
            if(StringUtils.isBlank(tell)){
                tell = mobileQueueService.findYYValue(yyID);
            }
            try {
                //添加记录
                mobileSilentService.insertValue(number, areaId, null, null, null,tell,0);
//                if(flag){
//                    //判断是否已发送排队信息
//                    //获取排队结果
//                    //异步短信发送
//                    Map<String, Object> map = mobileSilentService.getQueueValue(number, areaId);
//                    map.put("num",waitNum);
//                    if(StringUtils.isNotBlank(areaNameValue)){
//                        send.sendSMSQueueInfo(tell,number+"("+areaNameValue+")",map);
//                    }else{
//                        send.sendSMSQueueInfo(tell,number,map);
//                    }
//                }
                return AjaxJson.success().put("url", url + "?areaId=" + areaId + "&number=" + number +  "&tell="+ tell);
            } catch (Exception e) {
                logger.error("number:" + number +" reason: "+e.getMessage());
                return AjaxJson.error(e.getMessage());
            }
        } else {
            return AjaxJson.error("number：" + number+" reason : areaId or number is null");
        }
    }

    //排队机接口 用于人才验证
    @PostMapping("/isGXRC")
    public AjaxJson isGXRC(String idcard){
        //0否 1是 人才判断
        return AjaxJson.success().put("isCheck", Des3Utils.toCheckUserRC(idcard, userCheckRC));
    }

    /**
     * 融合指令监控
     * doBaseValue
     * tell电话 String
     * areaId点位id String
     * number排队编号 String
     * winNo 窗口号 列：1号窗口 String
     * waitNum 等待人数 int(无人数 0填充)
     * userNo 坐席人员工号 String
     * idcard 身份证号 String
     * yyID 预约id String
     * type 指令类型 int
     *
     * type指令： 0：取号；参数 areaId,number，tell，waitNum 返回url参数生成二维码打印在取票纸上
     *           1：叫号 ；参数 areaId number，winNo ，userNo，waitNum 无返回参数
     *           2：重呼 ；参数 areaId number，winNo ，userNo，waitNum 无返回参数
     *           3：结束办理；参数 areaId number，winNo ，userNo，waitNum 无返回参数
     *           4：弃号；参数 areaId number，winNo ，userNo，waitNum 无返回参数
     *           5：预约查询；参数 areaId idcard 返回参数yyID（预约id），businessid（业务 id），serial（业务编码）
     *           6：预约取号；参数 yyID，number无返回参数
     *           7：办理 未处理
     *           8:二维码解密返回用户数据
     *           9:电子社保二维码扫码取号
     *           -1：标记用户是否扫码
     *           -2:暂停 参数 areaId（点位id） winNo（窗口号） userNo（坐席人员工号） 无返回参数
     *           -3:特呼 参数 areaId winNo userNo 无返回参数
     *           -4:恢复 参数 areaId winNo userNo 无返回参数
     *           -5:转移 参数 areaId winNo userNo 无返回参数
     *           -6:登录操作 参数 areaId winNo userNo 无返回参数
     *           -7:切换登录 参数 areaId winNo userNo 无返回参数
     *
     * @author azj
     * @version 2020-04-24
     */
    @PostMapping("/doBaseValue")
    public AjaxJson doBaseValue(Integer type, Integer waitNum, String tell, String areaId, String number, String winNo, String userNo, String idcard, String yyID, String Qrcode) {
        if(type == 9 && StringUtils.isNotBlank(Qrcode)){
            send.intoSHBZKHistory(Qrcode);
            String result = GaoXinFwjcptTest.toSHBZK(Qrcode.trim(), null,ybj_url,ybj_accessKey,ybj_privateKey,ybj_appid,ybj_appSecret);
            //调用记录
            userService.intoUserHistory(Qrcode,"排队取号指令监控","指令:"+type+";返回结果:"+result,"无","无","无");
            //mobileIndexService.intoQrcode(Qrcode,result);
            if(StringUtils.isNotBlank(result) && result.contains("aac002")){
                JSONObject jsonObject = JSONObject.fromObject(result);
                return AjaxJson.success().put("idcard",jsonObject.getString("aac002")).put("name",jsonObject.getString("aac003"));
            }else{
                logger.error("保障卡解码错误result:"+result);
                return AjaxJson.error("保障卡二维码已失效！");
            }
        }else{
            //调用记录
            userService.intoUserHistory("无","排队取号指令监控","指令:"+type,number,areaId,tell);
            String areaNameValue = mobileSilentService.findAreaNameValue(areaId);
            if(type == 0){
                //异步记录取号数据
                send.intoWaitPersonHistory(areaId,number,tell,waitNum,idcard);
                if(getAge(idcard)>=60 && null!=tell && !"".equals(tell)){
                    send.sendWarnSMSInfo(tell,areaId,number);
                }
                //同步
                AjaxJson result = this.getUrl(areaId, number, tell, toUrl, waitNum, yyID, areaNameValue);
                //异步记录调用记录
                send.intoUserHistory(type, waitNum, tell, areaId, number, winNo, userNo, idcard, yyID,result.toString());
                return result;
            }else if(type == 1){
                //异步
                //send.estabgetQueuingUp(number,areaId);
                //异步
                this.toSendSMSAndWX(areaId,number,winNo,areaNameValue);
                queueSend.queuingInfoStart(number,areaId,winNo,userNo);
                if(mobileSilentService.findCountToYY(areaId,number)>=1){
                    //异步语音呼叫 指定窗口
                    send.setVoiceByIp("请"+number+"到"+winNo+"办理业务");
                }
            }else if(type == 2){
                //异步
                this.toOnlySendSMSAndWX(areaId,number,winNo,areaNameValue);
                if(mobileSilentService.findCountToYY(areaId,number)>=1 && mobileSilentService.selectNumberCount(areaId,number)<=3){
                    //异步语音呼叫 指定窗口
                    send.setVoiceByIp("请"+number+"到"+winNo+"办理业务");
                }
            }else if(type == 3){
                //异步
                //send.estabgetBanJie(number,areaId);
                //发生评价通知
                send.sendPJWX(areaId,number,winNo);
                if(gongAnOrgrizeId.equals(areaId)){
                    send.queueTimeSynchronous(type,number,gongAnUrl,winNo);
                }
                queueSend.queuingInfoEnd(number,areaId);
            }else if(type == 4){
                //异步
                //send.estabgetBanJie(number,areaId);
                if(gongAnOrgrizeId.equals(areaId)){
                    send.queueTimeSynchronous(type,number,gongAnUrl,winNo);
                }
            }else if(type == 5){
                //同步执行
                return send.checkUserYY(areaId,idcard);
            }else if(type == 6){
                //同步执行
                return AjaxJson.success().put("status",send.updateUserYY(yyID,number));
            }else if(type == 8){
                try{
                    return AjaxJson.success("操作成功！").put("data", EncryptUtils.aesDecrypt(idcard, GX_PUBLIC_KEY));
                }catch (Exception e){
                    e.printStackTrace();
                    return  AjaxJson.error("无效二维码！");
                }
            }else if(type == -2){
                //监察对接，1为回归2为暂停
                queueSend.windowStatus(areaId,winNo,"2");
            }else if(type == -4){
                queueSend.windowStatus(areaId,winNo,"1");
            }
            return AjaxJson.success("操作成功！");
        }
    }


    /**
     * 添加网上取票数据 临时取号
     *
     * @return
     */
    @PostMapping("intoUserQRLS")
    public AjaxJson  intoUserQRLS(String typeNumber,String orgrizeId,String tell) {
        HashMap<String,Object> mapResult = new HashMap<>();
        //临时取号信息
        MobileUserQR qr = userService.getUserIdcard("oyyT9s8WTu-wfSt3ZX2QSnC6FbbU");
        qr.setTell(tell);
        synchronized(this) {
            JSONObject json = null;
            String result = HttpQueueUtils.intoQueue(QueueUrl, qr.getIdcard(), qr.getName(), typeNumber, orgrizeId);
            //调用记录
            userService.intoUserHistory(UserUtils.getUser().getLoginName(),"线上取号","返回结果:"+result,typeNumber,orgrizeId,UserUtils.getUser().getPhone());
            if (StringUtils.isNotBlank(result)) {
                try {
                    json = JSONObject.fromObject(result);
                    if(result.contains("second")){
                        result = json.getString("second");
                        json = JSONObject.fromObject(result).getJSONObject("data");
                    }else{
                        result = json.getString("data");
                        json = JSONObject.fromObject(result);
                    }
                    //添加记录
                    String number = json.getString("number");
                    mobileSilentService.insertGXValue(number, orgrizeId, null, null, null,qr.getTell(),0);
                    //添加线上取号记录
                    mobileSilentService.insertOnLine(number, orgrizeId, null, null, null,qr.getTell(),0);
                    //判断是否已发送排队信息
                    //获取排队结果
                    //异步短信发送
                    Map<String, Object> map = mobileSilentService.getQueueValue(number, orgrizeId);
                    map.put("num",map.get("num"));
                    String areaNameValue = mobileSilentService.findAreaNameValue(orgrizeId);
                    send.intoWaitPersonHistory(orgrizeId,number,qr.getTell(),Integer.parseInt(String.valueOf(map.get("num"))),"");
                    if(StringUtils.isNotBlank(areaNameValue)){
                        number += "("+areaNameValue+")";
                    }
                    send.sendSMSQueueInfo(qr.getTell(),number,map);
                    mapResult.put("number",number);
                    mapResult.put("num",map.get("num"));
                    mapResult.put("areaName",map.get("areaName"));
                    mapResult.put("typeName",map.get("typeName"));
                    mapResult.put("waitTime",map.get("waitTime"));
                    mapResult.put("waitDoTime",map.get("waitDoTime"));
                    mapResult.put("appraiseStatus",2);
                    return AjaxJson.success().put("data",mapResult);
                } catch (Exception e) {
                    logger.error("orgrizeId:"+orgrizeId+"添加排队编号失败！result:"+result+"message:"+e.getMessage());
                    mapResult.put("message","请勿重复取号!");
                }
            }else{
                mapResult.put("message","网络延迟，请稍后再试!");
            }
        }
        mapResult.put("appraiseStatus",3);
        return AjaxJson.error("请勿重复操作！").put("code", 400).put("data",mapResult);
    }

    /**
     * 添加网上取票数据 临时取号 税务
     *
     * @return
     */
    @PostMapping("intoUserQRSW")
    public AjaxJson  intoUserQRLS(@RequestHeader("AppKey") String AppKey,String typeNumber,String orgrizeId,String tell,String name,String idcard) {
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        HashMap<String,Object> mapResult = new HashMap<>();
        if(mobileQueueService.findUserQueue(typeNumber,orgrizeId,idcard) >= 1){
            mapResult.put("message","该身份证还有未办结件!");
            return AjaxJson.error("该身份证还有未办结件！").put("code",400).put("data",mapResult);
        }
        //临时取号信息
        MobileUserQR qr = new MobileUserQR();
        qr.setTell(tell);
        qr.setIdcard(idcard);
        qr.setName(name);
        synchronized(this) {
            JSONObject json = null;
            String result = HttpQueueUtils.intoQueue(QueueUrl, qr.getIdcard(), qr.getName(), typeNumber, orgrizeId);
            //调用记录
            userService.intoUserHistory(idcard,"税务号","返回结果:"+result,typeNumber,orgrizeId,tell);
            if (StringUtils.isNotBlank(result)) {
                try {
                    json = JSONObject.fromObject(result);
                    if(result.contains("second")){
                        result = json.getString("second");
                        json = JSONObject.fromObject(result).getJSONObject("data");
                    }else{
                        result = json.getString("data");
                        json = JSONObject.fromObject(result);
                    }
                    //添加记录
                    String number = json.getString("number");
                    mobileSilentService.insertGXValue(number, orgrizeId, null, null, null,qr.getTell(),0);
                    //添加线上取号记录
                    mobileSilentService.insertOnLine(number, orgrizeId, null, null, null,qr.getTell(),0);
                    //判断是否已发送排队信息
                    //获取排队结果
                    //异步短信发送
                    Map<String, Object> map = mobileSilentService.getQueueValue(number, orgrizeId);
                    map.put("num",Integer.parseInt(String.valueOf(map.get("num"))));
                    String areaNameValue = mobileSilentService.findAreaNameValue(orgrizeId);
                    send.intoWaitPersonHistory(orgrizeId,number,qr.getTell(),Integer.parseInt(String.valueOf(map.get("num"))),"");
                    if(StringUtils.isNotBlank(areaNameValue)){
                        number += "("+areaNameValue+")";
                    }
                    send.sendSMSQueueInfo(qr.getTell(),number,map);
                    mapResult.put("number",number);
                    mapResult.put("num",map.get("num"));
                    mapResult.put("areaName",map.get("areaName"));
                    mapResult.put("typeName",map.get("typeName"));
                    mapResult.put("waitTime",map.get("waitTime"));
                    mapResult.put("waitDoTime",map.get("waitDoTime"));
                    mapResult.put("blCount",json.getString("serveCounter"));
                    mapResult.put("appraiseStatus",2);
                    //同步
                    AjaxJson jsonResult = this.getUrl(orgrizeId, json.getString("number"), tell, toUrl, Integer.parseInt(String.valueOf(map.get("num"))), "", areaNameValue);
                    mapResult.put("QRUrl",jsonResult.get("url"));
                    return AjaxJson.success().put("data",mapResult);
                } catch (Exception e) {
                    logger.error("orgrizeId:"+orgrizeId+"添加排队编号失败！result:"+result+"message:"+e.getMessage());
                    mapResult.put("message","请勿重复取号!");
                }
            }else{
                mapResult.put("message","网络延迟，请稍后再试!");
            }
        }
        mapResult.put("appraiseStatus",3);
        return AjaxJson.error("请勿重复操作！").put("code", 400).put("data",mapResult);
    }

    /**
     * 市上社会保障卡解码 gx
     */
    @PostMapping("checkSHBZK")
    public AjaxJson checkSHBZK(String Qrcode,String Authcode) {
        String result = GaoXinFwjcptTest.toSHBZK(Qrcode, Authcode,ybj_url,ybj_accessKey,ybj_privateKey,ybj_appid,ybj_appSecret);
        mobileIndexService.intoQrcode(Qrcode,result);
        if(StringUtils.isNotBlank(result) && result.contains("aac002")){
            JSONObject jsonObject = JSONObject.fromObject(result);
            return AjaxJson.success().put("idcard",jsonObject.getString("aac002")).put("name",jsonObject.getString("aac003"));
        }else{
            logger.error("保障卡解码错误result:"+result);
            return AjaxJson.error("保障卡参数错误！");
        }

    }

    /**
     * 市上社会保障卡解码 pengzhou
     */
//    @PostMapping("checkSHBZKPZ")
//    public AjaxJson checkSHBZKPZ(String Qrcode,String Authcode) {
//        String result = GaoXinFwjcptTest.toSHBZKPZ(Qrcode, Authcode,pz_ybj_url,pz_ybj_accessKey,pz_ybj_privateKey,pz_ybj_appid,pz_ybj_appSecret);
//        mobileIndexService.intoQrcode(Qrcode,result);
//        return AjaxJson.success();
//
//    }

    /**
     * 获取直接人脸验证后台传身份信息验证
     */
    @GetMapping("checkCardNameUrl")
    public AjaxJson checkCardNameUrl(@RequestHeader("AppKey") String AppKey,String name,String idcard,String url) {
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        String message = CheckFace.getNoCardNameUrl(SecretId, SecretKey, url,name,idcard);
        if (message == null) {
            return AjaxJson.error("获取人脸验证url失败！" + message);
        } else {
            JSONObject obj = JSONObject.fromObject(message);
            if (org.apache.commons.lang.StringUtils.isNotBlank(obj.getString("Url"))) {
                return AjaxJson.success().put("url", obj.getString("Url"));
            } else {
                logger.error("获取人脸验证url失败！" + message);
                return AjaxJson.error("获取人脸验证url失败！" + message);
            }
        }
    }

    /**
     * 获取用户人脸结果验证
     * bizToken
     * getUserFaceValue
     * @return
     */
    @GetMapping("getUserFaceValue")
    public AjaxJson getUserFaceValue(@RequestHeader("AppKey") String AppKey,String bizToken){
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        String result = CheckFace.GetDetectInfoText(SecretId, SecretKey, bizToken);
        if(null == result || "".equals(result)){
            return AjaxJson.success().put("check",false);
        }else{
            JSONObject obj = JSONObject.fromObject(result);
            obj = JSONObject.fromObject(obj.get("DetectInfo"));
            if("成功".equals(obj.getJSONObject("Text").getString("ErrMsg"))){
                return AjaxJson.success().put("check",true);
            }else{
                return AjaxJson.success().put("check",false);
            }
        }
    }

    /**
     * 窗口人员超时推送
     */
    @PostMapping("findOvertimeValue")
    @CrossOrigin(origins = "*")
    public AjaxJson findOvertimeValue(@RequestHeader("AppKey") String AppKey) {
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        //if(DateUtils.getDate().equals(CacheUtils.get("findOvertimeValue")))return AjaxJson.error("暂无数据");
        //CacheUtils.put("findOvertimeValue", DateUtils.getDate());
        return AjaxJson.success().put("data",manageDuration.getManageDurationValue()).put("ymbcsCount",mobileIndexService.findYMBCSCount());
    }

    /**
     * 清空推送窗口人员超时数据
     */
    @GetMapping("cleanOvertimeValue")
    public void cleanOvertimeValue() {
        CacheUtils.remove("cleanOvertimeValue");
    }

    /**
     * 获取高馨办注册，网上取号数，预约数据，访问数据 加载至前端
     * gxbListValueQD
     * @return
     */
    @PostMapping("gxbListValueQD")
    public AjaxJson gxbListValueQD(@RequestHeader("AppKey") String AppKey,String startTime,String endTime){

        startTime = startTime+" 00:00:00";
        endTime = endTime+" 23:59:59";
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        Map<String,Object> gxb = new HashMap <String,Object>();
        List <Integer> list = mobileIndexService.gxbListValueQD(startTime,endTime);
        List <Integer> yylist = mobileSilentService.yyListValueQD(startTime,endTime);
        List <Integer> ymbcs = mobileSilentService.ymbcsValueListQD(startTime,endTime);
        //高馨办注册量
        gxb.put("registerCount",list.get(0));
        //高馨办网上取号量
        gxb.put("queueCount",yylist.get(1));
        //高馨办预约量
        gxb.put("yyCount",yylist.get(0));
        //高馨办访问纬度统计
        gxb.put("visitCount",list.get(3));
        //一码办成事个人空间量
        gxb.put("ymbcsUserCount",list.get(0));
        //一码办成事企业空间用户量
        gxb.put("ymbcsCompanyCount",list.get(5));
        //一码办成事材料数
        gxb.put("ymbcsMaterialsCount",list.get(1));
        //一码办成事办件量
        gxb.put("ymbcsCount",list.get(2));
        //一码办成事取号量
        gxb.put("codeCount",ymbcs.get(0));
        //一码办成事查询量
        gxb.put("findCount",ymbcs.get(1));
        //一码办成事自助取件量
        gxb.put("selfHelpCount",list.get(4));
        //一码办成事亮码量
        gxb.put("qrCount",list.get(6));
        return AjaxJson.success().put("data",gxb);
    }

    /**
     * 获取高馨办注册，网上取号数，预约数据，访问数据
     * gxbListValue
     * @return
     */
    @CrossOrigin(origins = "*")
    @PostMapping("gxbListValue")
    public AjaxJson gxbListValue(@RequestHeader("AppKey") String AppKey,String type){
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        Map<String,Object> gxb = new HashMap <String,Object>();
        gxb.put("visitList",mobileIndexService.gxbVisitValue(type));
        if(StringUtils.isNotBlank(type) && "year".equals(type)){
            type = "all";
        }
        List <Integer> list = mobileIndexService.gxbListValue(type);
        List <Integer> yylist = mobileSilentService.yyListValue(type);
        List <Integer> ymbcs = mobileSilentService.ymbcsValueList(type);
        //高馨办注册量
        gxb.put("registerCount",list.get(0));
        //高馨办网上取号量
        gxb.put("queueCount",yylist.get(1));
        //高馨办预约量
        gxb.put("yyCount",yylist.get(0));
        //高馨办访问纬度统计
        gxb.put("visitCount",list.get(3));
        //一码办成事个人空间量
        gxb.put("ymbcsUserCount",list.get(0));
        //一码办成事企业空间用户量
        gxb.put("ymbcsCompanyCount",list.get(5));
        //一码办成事材料数
        gxb.put("ymbcsMaterialsCount",list.get(1));
        //一码办成事办件量
        gxb.put("ymbcsCount",list.get(2));
        //一码办成事取号量
        gxb.put("codeCount",ymbcs.get(0));
        //一码办成事查询量
        gxb.put("findCount",ymbcs.get(1));
        //一码办成事自助取件量
        gxb.put("selfHelpCount",list.get(4));
        return AjaxJson.success().put("data",gxb);
    }
    /**
     * 获取高馨办部分可导办事项
     * gxbListValue
     * @return
     */
    @CrossOrigin(origins = "*")
    @PostMapping("gxbMatterList")
    public AjaxJson gxbMatterList(@RequestHeader("AppKey") String AppKey){
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        return AjaxJson.success().put("data",mobileIndexService.matterListLinShi());
    }

    /**
     * 获取高馨办智能推荐
     * gxbListValue
     * @return
     */
    @CrossOrigin(origins = "*")
    @PostMapping("gxbMatterOffices")
    public AjaxJson gxbMatterList(@RequestHeader("AppKey") String AppKey,String oid){
        ServiceOfficesQuery sq = new ServiceOfficesQuery();
        sq.setMatterId(oid);
        Double la = 104.07;
        Double lo = 30.59;
        sq.setPosition(new Double[]{la,lo});
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        return AjaxJson.success().put("data",appointmentService.findServeOffices(sq));
    }

    /**
     * 获取一码办成事用户数据
     * gxbListValue
     * @return
     */
    @CrossOrigin(origins = "*")
    @PostMapping("ymbcsUserList")
    public AjaxJson ymbcsUserList(@RequestHeader("AppKey") String AppKey,String pageNo,String pageSize,String type){
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        pageSize = "5";
        return AjaxJson.success().put("data",mobileIndexService.ymbcsUserList(pageNo,pageSize,type));
    }

    /**
     * 获取一码办成事取号数据
     * gxbListValue
     * @return
     */
    @CrossOrigin(origins = "*")
    @PostMapping("ymbcsQueueList")
    public AjaxJson ymbcsQueueList(@RequestHeader("AppKey") String AppKey,String pageNo,String pageSize,String type){
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        pageSize = "5";
        PageBean <YmbcsUser> page = mobileSilentService.ymbcsQueueList(pageNo, pageSize, type);
        page.getDatas().stream().map(e -> {
            YmbcsUser ymbcsValue = mobileSilentService.findYmbcsValue(e.getAreaId(), e.getNumber(), e.getServiceTime());
            e.setName(ymbcsValue.getName());
            e.setCountName(ymbcsValue.getCountName() == null ? "":ymbcsValue.getCountName());
            e.setServiceTime(ymbcsValue.getServiceTime() == null ? "":ymbcsValue.getServiceTime());
            e.setTypeName(ymbcsValue.getTypeName());
            if("510109000001".equals(e.getAreaId())){
                e.setAreaName("（自贸）"+ymbcsValue.getAreaName());
            }else if("510109000003".equals(e.getAreaId())){
                e.setAreaName("（西区）"+ymbcsValue.getAreaName());
            }else{
                e.setAreaName("（南区）"+ymbcsValue.getAreaName());
            }
            ymbcsValue = null;
            return e;
        }).collect(Collectors.toList());
        return AjaxJson.success().put("data",page);
    }

    /**
     * 获取一码办成事取号数据
     * gxbListValue
     * @return
     */
    @CrossOrigin(origins = "*")
    @PostMapping("ymbcsQueueValueById")
    public AjaxJson ymbcsQueueValueById(@RequestHeader("AppKey") String AppKey,String userId){
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        return AjaxJson.success().put("data",mobileSilentService.ymbcsQueueValueById(userId).stream().map(e -> {
            YmbcsUser ymbcsValue = mobileSilentService.findYmbcsValue(e.getAreaId(), e.getNumber(), e.getServiceTime());
            e.setRegisterTime(e.getServiceTime());
            e.setName(ymbcsValue.getName());
            e.setTypeName(ymbcsValue.getTypeName());
            e.setCountName(ymbcsValue.getCountName() == null ? "":ymbcsValue.getCountName());
            e.setServiceTime(ymbcsValue.getServiceTime() == null ? "":ymbcsValue.getServiceTime());
            e.setEndTime(ymbcsValue.getEndTime() == null ? "":ymbcsValue.getEndTime());
            if("510109000001".equals(e.getAreaId())){
                e.setAreaName("（自贸）"+ymbcsValue.getAreaName());
            }else if("510109000003".equals(e.getAreaId())){
                e.setAreaName("（西区）"+ymbcsValue.getAreaName());
            }else{
                e.setAreaName("（南区）"+ymbcsValue.getAreaName());
            }
            List clList = new ArrayList<>();
            e.setMaterialCount(1);
            clList.add("身份证复印件");
            e.setMaterialList(clList);
            ymbcsValue = null;
            return e;
        }).collect(Collectors.toList()));
    }

    /**
     * 获取一码办成事查询数据
     * gxbListValue
     * @return
     */
    @CrossOrigin(origins = "*")
    @PostMapping("ymbcsFindList")
    public AjaxJson ymbcsFindList(@RequestHeader("AppKey") String AppKey,String pageNo,String pageSize,String type){
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        pageSize = "5";
        PageBean <YmbcsUser> page = mobileSilentService.ymbcsFindList(pageNo, pageSize, type);
        page.getDatas().stream().map(e -> {
            YmbcsUser ymbcsValue = mobileSilentService.findYmbcsValue(e.getAreaId(), e.getNumber(), e.getServiceTime());
            e.setName(ymbcsValue.getName());
            e.setTypeName(ymbcsValue.getTypeName());
            e.setCountName(ymbcsValue.getCountName() == null ? "":ymbcsValue.getCountName());
            e.setServiceTime(ymbcsValue.getServiceTime() == null ? "":ymbcsValue.getServiceTime());
            if("510109000001".equals(e.getAreaId())){
                e.setAreaName("（自贸）"+ymbcsValue.getAreaName());
            }else if("510109000003".equals(e.getAreaId())){
                e.setAreaName("（西区）"+ymbcsValue.getAreaName());
            }else{
                e.setAreaName("（南区）"+ymbcsValue.getAreaName());
            }
            ymbcsValue = null;
            return e;
        }).collect(Collectors.toList());
        return AjaxJson.success().put("data",page);
    }

    /**
     * 获取一码办成事取号数据
     * gxbListValue
     * @return
     */
    @CrossOrigin(origins = "*")
    @PostMapping("ymbcsFindValueById")
    public AjaxJson ymbcsFindValueById(@RequestHeader("AppKey") String AppKey,String userId,String number,String areaId,String serviceTime){
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        return AjaxJson.success().put("data",mobileSilentService.ymbcsFindValueById(userId).stream().map(e -> {
            YmbcsUser ymbcsValue = mobileSilentService.findYmbcsValue(e.getAreaId(), e.getNumber(), e.getServiceTime());
            e.setRegisterTime(e.getServiceTime());
            e.setName(ymbcsValue.getName());
            e.setTypeName(ymbcsValue.getTypeName());
            e.setCountName(ymbcsValue.getCountName() == null ? "":ymbcsValue.getCountName());
            e.setServiceTime(ymbcsValue.getServiceTime() == null ? "":ymbcsValue.getServiceTime());
            e.setEndTime(ymbcsValue.getEndTime() == null ? "":ymbcsValue.getEndTime());
            if("510109000001".equals(e.getAreaId())){
                e.setAreaName("（自贸）"+ymbcsValue.getAreaName());
            }else if("510109000003".equals(e.getAreaId())){
                e.setAreaName("（西区）"+ymbcsValue.getAreaName());
            }else{
                e.setAreaName("（南区）"+ymbcsValue.getAreaName());
            }
            List clList = new ArrayList<>();
            e.setMaterialCount(1);
            clList.add("身份证复印件");
            e.setMaterialList(clList);
            ymbcsValue = null;
            return e;
        }).collect(Collectors.toList()));
    }

    /**
     * 获取一码办件统计
     * ymbcsTypeNameList
     * @return
     */
    @CrossOrigin(origins = "*")
    @PostMapping("ymbcsTypeNameList")
    public AjaxJson ymbcsTypeNameList(@RequestHeader("AppKey") String AppKey,String type){
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        return AjaxJson.success().put("data",mobileIndexService.ymbcsTypeNameList(type));
    }



    /**
     * 获取一码办成事用户办件详细数据
     * ymbcsUserValueById
     * @return
     */
    @CrossOrigin(origins = "*")
    @PostMapping("ymbcsUserValueById")
    public AjaxJson ymbcsUserValueById(@RequestHeader("AppKey") String AppKey,String userId){
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        List <YmbcsValue> list = mobileIndexService.ymbcsUserValueById(userId);
        for(YmbcsValue yv : list){
            Integer count = mobileIndexService.ymbcsMaterialNum(yv.getUserId());
            yv.setMaterialCount(count);
            //yv.setEndTime(mobileSilentService.ymbcsEndTime(yv.getNumber(),yv.getServiceTime()));
            String result = mobileIndexService.findListByName(yv.getTypeName(), versionService.getVersion());
            List clList = new ArrayList<>();
            if(StringUtils.isNotBlank(result)){
                JSONArray json = JSONArray.fromObject(result);
                if(count <= json.size())count=json.size();
                for(int i=0;i<json.size();i++){
                    clList.add(json.getJSONObject(i).getString("rawMaterialName"));
                }
            }else{
                count=1;
                clList.add("身份证复印件");
                if(yv.getTypeName().equals("营业执照遗失补领换发申请")){
                    count = count+2;
                    clList.add("核发证照情况表");
                    clList.add("市场主体登记证照核发和归档记录表");
                }
            }

            yv.setMaterialCount(count);
            yv.setMaterialList(clList);
        }
        return AjaxJson.success().put("data",list);
    }

    /**
     * 获取一码办成事用户办件详细数据
     * getManageDurationTime
     * @return
     */
    @CrossOrigin(origins = "*")
    @PostMapping("getManageDurationTime")
    public AjaxJson getManageDurationTime(@RequestHeader("AppKey") String AppKey){
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        return manageDuration.getManageDurationTime(false);
    }



    /**
     * 获取高新区部门网办率
     * departmentList
     * @return
     */
    @CrossOrigin(origins = "*")
    @PostMapping("departmentList")
    public AjaxJson departmentList(@RequestHeader("AppKey") String AppKey){
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        return  AjaxJson.success().put("data",manageDuration.departmentList());
    }


    /**
     *  根据身份证号判断当前年龄
     * @param cardNo
     * @return
     */
    public static int getAge(String cardNo) {

        try {
            if(cardNo.length() <= 18)return 1;
            String birthday = cardNo.substring(6, 14);
            Date birthdate = null;
            birthdate = new SimpleDateFormat("yyyyMMdd").parse(birthday);
            GregorianCalendar currentDay = new GregorianCalendar();
            currentDay.setTime(birthdate);
            int birYear = currentDay.get(Calendar.YEAR);

            // 获取年龄
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
            String thisYear = simpleDateFormat.format(new Date());
            int age = Integer.parseInt(thisYear) - birYear;
            return age;
        } catch (ParseException e) {
            return 1;
        }

    }

    /**
     * 获取群众数据通过用户手机号 对接卓繁
     * userId用户id
     * @return
     */
    @GetMapping("ymbcsUserByTell")
    public AjaxJson ymbcsUserByTell(@RequestHeader("AppKey") String AppKey,String tell){
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        YmbcsUserZF ym = userService.ymbcsUserByTell(tell);
        if(null == ym){
            return AjaxJson.error("暂无此数据！");
        }else{
            try{
                return AjaxJson.success().put("data",EncryptUtils.aesEncrypt(JSONObject.fromObject(ym).toString(), GX_PUBLIC_KEY));
            }catch (Exception e){
                e.printStackTrace();
                return  AjaxJson.error("无效数据！");
            }
        }
    }

    /**
     * 一码办成事用户扫二维码进行人脸认证  扫码取件环境 对接市场监管局
     *
     */
    @RequestMapping(value = "/ymbcsUserCheckUrl", method = RequestMethod.GET)
    public AjaxJson ymbcsUserCheckUrl(@RequestHeader("AppKey") String AppKey) {
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        String uuid = UUID.randomUUID().toString();
        return AjaxJson.success().put("url",faceCheckQR+uuid).put("uuid",uuid);
    }

    /**
     * 一码办成事用户扫二维码进行人脸认证  获取扫码用户信息 对接市场监管局
     *
     */
    @RequestMapping(value = "/ymbcsUserValueQR", method = RequestMethod.GET)
    public AjaxJson ymbcsUserValueQR(@RequestHeader("AppKey") String AppKey,String uuid) {
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        if(StringUtils.isBlank(uuid)) return AjaxJson.error("uuid is error!").put("code", 400);
        HashMap <String, String> map = userService.ymbcsUserValueQR(uuid);
        if(null == map) return AjaxJson.error("人脸核身已超时，请重新扫码认证!").put("code", 400);
        try{
            return AjaxJson.success().put("data",EncryptUtils.aesEncrypt(JSONObject.fromObject(map).toString(), GX_PUBLIC_KEY));
        }catch (Exception e){
            logger.error(e.getMessage());
            return  AjaxJson.error("无效数据！");
        }
    }



    /**
     * 一码办成事用户数据二维码对接卓繁
     *
     */
    @RequestMapping(value = "/ymbcsUserValue", method = RequestMethod.GET)
    public AjaxJson ymbcsUserValue(@RequestHeader("AppKey") String AppKey,String uuid) {
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        if(StringUtils.isNotBlank(uuid) && uuid.lastIndexOf("/") >= 0){
            uuid = uuid.substring(uuid.lastIndexOf("/")+1,uuid.length());
        }
        if(StringUtils.isNotBlank(uuid)){
            if(StringUtils.isBlank(userService.findKey(uuid,loseTime))){
                return  AjaxJson.error("二维码已失效！");
            }
        }
        MobileGxUser mu = userService.getGxUserCode(uuid);
        if(null == mu){
            return AjaxJson.error("暂无此数据！");
        }else{
            mu.setBirthday(mu.getIdcard().substring(6,10));
            int sex = Integer.parseInt(mu.getIdcard().substring(16,17));
            if (sex % 2 == 0) {
                mu.setSex("女");
            } else {
                mu.setSex("男");
            }
            mu.setList(userService.findUserMaterial(mu.getIdcard()));
            try{
                mobileIndexService.intoUserZZQJ( mu.getName(), mu.getIdcard(), mu.getTell());
                return AjaxJson.success().put("data",EncryptUtils.aesEncrypt(JSONObject.fromObject(mu).toString(), GX_PUBLIC_KEY));
            }catch (Exception e){
                e.printStackTrace();
                return  AjaxJson.error("无效二维码！");
            }

        }
    }
    /**
     * 一码办成事用户上传图片对接卓繁
     *
     */
    @RequestMapping(value = "/ymbcsUserImgs", method = RequestMethod.GET)
    public AjaxJson ymbcsImgsImages(@RequestHeader("AppKey") String AppKey,String id) {
        if (!AppKeyValue.equals(AppKey)) return AjaxJson.error("AppKey is error!").put("code", 400);
        String url = electronicMaterialService.getURLById(id);
        if (!"".equals(url) && null != url) {
            url = url.replace("/api", "");
            String fileDir = FileKit.getFileUrl(url);
            try{
                return AjaxJson.success().put("data",EncryptUtils.aesEncrypt(getImgBase64Str(fileDir), GX_PUBLIC_KEY));
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return  AjaxJson.error("无效id！");
    }
    public  String getImgBase64Str(String imgFile) {
        // 将图片文件转化为字节数组字符串，并对其进行Base64编码处理
        InputStream in = null;
        byte[] data = null;
        // 读取图片字节数组
        try {
            in = new FileInputStream(imgFile);
            data = new byte[in.available()];
            in.read(data);
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return org.apache.commons.codec.binary.Base64.encodeBase64String(data);
    }


}

